﻿#region License
// (c) Intergen.
// This source is subject to the Microsoft Public License (Ms-PL).
// Please see http://go.microsoft.com/fwlink/?LinkID=131993 for details.
// All other rights reserved.
#endregion

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Xml.Linq;

namespace TextGlow.Control.Model
{
  public class Paragraph : DocumentContent
  {
    public static readonly XName Name = Document.WordprocessingML + "p";

    private ParagraphProperties _properties;
    private List<InlineContent> _content = new List<InlineContent>();

    public List<InlineContent> Content
    {
      get { return _content; }
      set { _content = value; }
    }

    public ParagraphProperties Properties
    {
      get { return _properties; }
      set { _properties = value; }
    }

    public Paragraph(Content parent, XElement element)
      : base(parent)
    {
      if (element == null)
        throw new ArgumentNullException("element");

      XNamespace ns = element.Name.Namespace;

      _properties = new ParagraphProperties(this, element.Element(ns + "pPr"));

      _content.AddRange(InlineContent.Create(this, element.Elements()));
    }

    public override string ToString()
    {
      StringBuilder sb = new StringBuilder();

      foreach (InlineContent content in _content)
      {
        sb.Append(content.ToString());
      }

      return sb.ToString();
    }
  }
}